package com.simple.piger.controller;

import com.google.common.collect.Lists;
import com.simple.piger.dto.ComboRespDto;
import com.simple.piger.enums.*;
import com.simple.piger.service.AreaDistrictService;
import com.simple.piger.utils.AjaxResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author baolw
 */
@RestController
public class CommonController extends BaseController {
    @Autowired
    private AreaDistrictService areaDistrictService;

    /**
     * 返回学历信息，人员性别， 公司规模，公司人数下拉选的接口
     * @param type
     * @return
     */
    @GetMapping("/cms/common/combo/result/{type}")
    public AjaxResult getCommonComboResult(@PathVariable("type") String type) {
        List<ComboRespDto> list = Lists.newArrayList();
        if (StringUtils.equals("edu", type)) {
            for (ApplyUserEduEnums eduEnums : ApplyUserEduEnums.values()) {
                ComboRespDto respDto = new ComboRespDto();
                respDto.setCode(eduEnums.getItem());
                respDto.setValue(eduEnums.getDesc());
                list.add(respDto);
            }
        } else  if (StringUtils.equals("userStatus", type)) {
            for (ApplyUserStatusEnums eduEnums : ApplyUserStatusEnums.values()) {
                ComboRespDto respDto = new ComboRespDto();
                respDto.setCode(eduEnums.getItem());
                respDto.setValue(eduEnums.getDesc());
                list.add(respDto);
            }
        } else  if (StringUtils.equals("gender", type)) {
            for (GenderEnums eduEnums : GenderEnums.values()) {
                ComboRespDto respDto = new ComboRespDto();
                respDto.setCode(eduEnums.getItem());
                respDto.setValue(eduEnums.getDesc());
                list.add(respDto);
            }
        } else  if (StringUtils.equals("financing", type)) {
            for (InviteCompanyFinancingEnums eduEnums : InviteCompanyFinancingEnums.values()) {
                ComboRespDto respDto = new ComboRespDto();
                respDto.setCode(eduEnums.getItem());
                respDto.setValue(eduEnums.getDesc());
                list.add(respDto);
            }
        } else  if (StringUtils.equals("scale", type)) {
            for (InviteCompanyScaleEnums eduEnums : InviteCompanyScaleEnums.values()) {
                ComboRespDto respDto = new ComboRespDto();
                respDto.setCode(eduEnums.getItem());
                respDto.setValue(eduEnums.getDesc());
                list.add(respDto);
            }
        }
        return success(list);
    }

    /**
     * 返回  省份下拉选的接口。
     * @param provinceCode
     * @return
     */
    @GetMapping("/cms/common/combo/provinceList")
    public AjaxResult getProvinceList(@RequestParam(value = "provinceCode", required = false) String provinceCode) {
        return areaDistrictService.getProvinceList(provinceCode);
    }

    /**
     * 返回城市下拉选的接口
     * @param provinceCode
     * @return
     */
    @GetMapping("/cms/common/combo/cityList")
    public AjaxResult getCityList(@RequestParam("provinceCode") String provinceCode) {
        return areaDistrictService.getCityList(provinceCode);
    }
}
